//
//  HomeYueViewCell.m
//  Shengzhuli
//
//  Created by FXGuo on 2017/7/13.
//  Copyright © 2017年 kamangkeji. All rights reserved.
//

#import "HomeYueViewCell.h"
#import <UIButton+WebCache.h>
#import "NSDate+Extension.h"

@interface HomeYueViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *bgImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLab;
@property (weak, nonatomic) IBOutlet UILabel *timeLab;
@property (weak, nonatomic) IBOutlet UILabel *addressLab;
@property (weak, nonatomic) IBOutlet UILabel *moneyLab;
@property (weak, nonatomic) IBOutlet UILabel *reportLab;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imgWCons;
@property (weak, nonatomic) IBOutlet UIImageView *playerView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *timeTopCons;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *addressBottomCons;

@property (weak, nonatomic) IBOutlet UIButton *reportBtn;
@property (weak, nonatomic) IBOutlet UILabel *lineBtn;


@end

@implementation HomeYueViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.imgWCons.constant = 0.5*ScreenW;
    if (IS_IPHONE_5) {
        self.timeTopCons.constant = 1;
        self.addressBottomCons.constant = 1;
    }
}
- (IBAction)reportClick:(UIButton *)btn
{
    if (self.reportBlock) {
        self.reportBlock(self.model);
    }
}
- (void)setIsFromPerson:(BOOL)isFromPerson
{
    isFromPerson = isFromPerson;
    self.reportBtn.hidden =YES;
    self.lineBtn.hidden = YES;
    self.reportLab.hidden = YES;
    self.moneyLab.text = self.model.status;
}
- (void)setType:(NSInteger)type
{
    _type = type;
    self.reportBtn.hidden = YES;
    self.lineBtn.hidden = YES;
}
- (void)setModel:(HomeYueModel *)model
{
    _model = model;
    [self.bgImageView sd_setImageWithURL:[NSURL URLWithString:model.activityPictureUrl] placeholderImage:GetImage(@"default_goods_image")];
    self.nameLab.text = model.title;
    self.addressLab.text = [NSString stringWithFormat:@"地址:%@",model.address];
    if (model.startDate != nil) {
        self.timeLab.text = [NSString stringWithFormat:@"举办时间:%@",[NSDate spToDateString:model.startDate]];
    }else {
        self.timeLab.text = @"";
    }
//    self.playerView.hidden = (model.videoUrl.length > 0)?NO:YES;
    NSString *str = @"";
    NSInteger count = 0;
    if ([model.type isEqualToString:@"2"]) {//活动已结束
        self.moneyLab.text = @"已结束";
        str = [NSString stringWithFormat:@"%zd人已浏览",model.viewCount];
        count = [NSString stringWithFormat:@"%zd",model.viewCount].length;
        self.reportBtn.hidden = YES;
        self.lineBtn.hidden = YES;
    }else {
        str = [NSString stringWithFormat:@"%zd人已报名",model.applyCount];
        count = [NSString stringWithFormat:@"%zd",model.applyCount].length;
        self.moneyLab.text = @"免费";
        self.reportBtn.hidden = NO;
        self.lineBtn.hidden = NO;
    }
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:str];
    [attrStr addAttributes:@{NSFontAttributeName:Font(11),NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#3285ff"]} range:NSMakeRange(0, count)];
    [attrStr addAttributes:@{NSFontAttributeName:Font(11),NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#888888"]} range:NSMakeRange(count, str.length-count)];
    self.reportLab.attributedText = attrStr;
    
}

@end
